﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Kooboo.HtmlFunc.Function;

namespace Kooboo.HtmlFunc.Analysis.Testers
{
    public class MultiFuncTester : IFuncTester
    {
        public const char FuncSeparator = '|';

        private IList<IFuncTester> Testers;
        public MultiFuncTester(string referenceText)
        {
            this.Testers = new List<IFuncTester>();
            var funcParts = referenceText.Split(FuncSeparator);
            foreach (var func in funcParts)
                this.Testers.Add(new ParametricTester(func));
        }

        public IFuncTester MatchedTester
        {
            get;
            private set;
        }

        #region IFuncTester Members

        public bool IsMatch(object real)
        {
            foreach (var tester in this.Testers)
            {
                var match = tester.IsMatch(real);
                if (match)
                {
                    this.MatchedTester = tester;
                    return true;
                }
            }

            return false;
        }

        #endregion
    }
}
